from datetime import datetime
from typing import Optional
from pydantic import BaseModel, Field
from app.core.constants import StorageProviderEnum


class FileResponse(BaseModel):
    """文件响应"""

    id: int = Field(..., description="文件ID")
    filename: str = Field(..., description="文件名")
    size: int = Field(..., description="文件大小")
    content_type: str = Field(..., description="文件类型")
    url: str = Field(..., description="访问URL")
    created_at: datetime = Field(..., description="创建时间")
    uploader_name: str = Field(..., description="上传者")

    class Config:
        from_attributes = True


class FileListRequest(BaseModel):
    """文件列表请求"""

    page: int = Field(1, ge=1, description="页码")
    page_size: int = Field(20, ge=1, le=100, description="每页数量")
    filename: Optional[str] = Field(None, description="文件名搜索")


class StorageProviderResponse(BaseModel):
    """存储供应商响应"""

    id: int = Field(..., description="供应商ID")
    name: str = Field(..., description="供应商名称")
    provider_type: StorageProviderEnum = Field(..., description="供应商类型")
    endpoint: Optional[str] = Field(None, description="访问端点")
    bucket: Optional[str] = Field(None, description="存储桶名称")
    region: Optional[str] = Field(None, description="区域")
    base_url: str = Field(..., description="基础访问URL")
    is_default: bool = Field(..., description="是否为默认供应商")
    is_active: bool = Field(..., description="是否启用")

    class Config:
        from_attributes = True


class StorageProviderCreateRequest(BaseModel):
    """创建存储供应商请求"""

    name: str = Field(..., min_length=2, max_length=50, description="供应商名称")
    provider_type: StorageProviderEnum = Field(..., description="供应商类型")
    access_key: Optional[str] = Field(None, max_length=100, description="AccessKey")
    secret_key: Optional[str] = Field(None, max_length=100, description="SecretKey")
    endpoint: Optional[str] = Field(None, max_length=200, description="访问端点")
    bucket: Optional[str] = Field(None, max_length=100, description="存储桶名称")
    region: Optional[str] = Field(None, max_length=50, description="区域")
    base_url: str = Field(..., max_length=200, description="基础访问URL")
    is_default: bool = Field(False, description="是否为默认供应商")


class StorageProviderUpdateRequest(StorageProviderCreateRequest):
    """更新存储供应商请求"""

    id: int = Field(..., description="供应商ID")
